package com.diyunapp.xilinapp.utils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpUtils {
	public static byte[] request(String urlpath){
		ByteArrayOutputStream baos=null;
		try {
			baos=new ByteArrayOutputStream();
			//1 ����URL
			URL url = new URL(urlpath);
			//2 ����openConnection����httpUrlConnection
			HttpURLConnection connection=(HttpURLConnection) url.openConnection();
			//3�����������
			connection.setConnectTimeout(10000);
			connection.setReadTimeout(10000);
			//4��������
			connection.connect();
			//5������Ӧ
			if(connection.getResponseCode()==200){
				InputStream is=connection.getInputStream();
				byte[] buf=new byte[1024*4];
				int len=0;
				while((len=is.read(buf))!=-1){
					baos.write(buf,0,len);
				}
				return baos.toByteArray();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}
}
